package com.cgx.tablet.beeper.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import android.widget.BaseAdapter;

import com.cgx.tablet.beeper.R;
import com.cgx.tablet.beeper.bean.BizWaitBean;
import com.yatoooon.screenadaptation.ScreenAdapterTools;

import java.util.List;

/**
 * Created by Administrator on 2018/9/18 0005.
 */

public class BizWaitAdapter extends BaseAdapter{

    private List<BizWaitBean> bizWaitBeans;
    private Context mContext;
    ViewHolder holder;
    LayoutInflater mInflater;

    public BizWaitAdapter(Context context, List<BizWaitBean> bizWaitBeans){
        mContext = context;
        this.bizWaitBeans = bizWaitBeans;
        this.mInflater = LayoutInflater.from(this.mContext);
    }

//    protected View newView(Context context, int position, ViewGroup viewGroup) {
//        View view = mInflater.inflate(R.layout.item_biz_wait, null);
//
//        BizWaitAdapter.ViewHolder holder = new BizWaitAdapter.ViewHolder();
//        holder.bizName = view.findViewById(R.id.biz_name);
//        holder.waitCount = view.findViewById(R.id.wait_count);
//        holder.nextTicket = view.findViewById(R.id.next_ticket);
//        view.setTag(holder);
//        ScreenAdapterTools.getInstance().loadView(view);
//        return view;
//    }
//
//    @Override
//    protected void bindView(View view, final int position, BizWaitBean bizWaitBean) {
//        BizWaitAdapter.ViewHolder holder = (ViewHolder) view.getTag();
//        holder.bizName.setText(bizWaitBean.getBizName());
//        holder.waitCount.setText(String.valueOf(bizWaitBean.getWaitCount()));
//        holder.nextTicket.setText(String.valueOf(bizWaitBean.getNextTicket()));
//    }
//
//    @Override
//    public long getItemId(int position) {
//        BizWaitBean bizWaitBean = this.getItem(position);
//        return bizWaitBean == null ? 0L:(long)bizWaitBean.hashCode();
//    }
//
//    private static class ViewHolder {
//        TextView bizName;
//        TextView waitCount;
//        TextView nextTicket;
//    }

    @Override
    public int getCount() {
        return bizWaitBeans.size() == 0 ?0:Integer.MAX_VALUE;
    }

    @Override
    public Object getItem(int position) {
        return bizWaitBeans.get(position % bizWaitBeans.size());
    }

    @Override
    public long getItemId(int position) {
        return position % bizWaitBeans.size();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView==null){
            convertView = mInflater.inflate(R.layout.item_biz_wait, null);
            holder = new ViewHolder();
            holder.bizName = convertView.findViewById(R.id.biz_name);
            holder.waitCount = convertView.findViewById(R.id.wait_count);
            holder.nextTicket = convertView.findViewById(R.id.next_ticket);
            convertView.setTag(holder);
            ScreenAdapterTools.getInstance().loadView(convertView);
        }else {
            holder= (ViewHolder) convertView.getTag();
        }

        holder.bizName.setText(bizWaitBeans.get(position % bizWaitBeans.size()).getBizName());
        holder.waitCount.setText(String.valueOf(bizWaitBeans.get(position % bizWaitBeans.size()).getWaitCount()));
        holder.nextTicket.setText(String.valueOf(bizWaitBeans.get(position % bizWaitBeans.size()).getNextTicket()));

        return convertView;
    }


    private static class ViewHolder {
        TextView bizName;
        TextView waitCount;
        TextView nextTicket;
    }

}
